package d1208.Ljs2.Ljs15;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.lang.reflect.Method;
import java.util.List;

public class Demo1 {

   // public static List<Animal> list= FileUtils.readLines(new File("E:\\代码\\代码练习和作业\\Zuoye12月6号\\src\\Ljs2\\Ljs15\\dataAnimal.txt"));

    public static void main(String[] args) throws Exception{
        List<String> list = FileUtils.readLines(new File("E:\\代码\\代码练习和作业\\Zuoye12月6号\\src\\Ljs2\\Ljs15\\dataAnimal.txt"));
        Class<?> aClass = Class.forName("Ljs2.Ljs15.Animal");
        Method getAnimal = aClass.getMethod("getAnimal");
        getAnimal.setAccessible(true);
        for (String s : list) {
            Class c = Class.forName(s.substring(0, s.indexOf(" ")));
            try {
                Cat cat = (Cat)c.getConstructor(String.class,String.class,String.class).newInstance(s.split("=")[1],s.split("=")[2],s.split("=")[3]);
                System.out.println(1);

            } catch (Exception e) {
                Dog dog=(Dog) c.getConstructor(String.class,String.class,int.class).newInstance(s.split("=")[1],s.split("=")[2],Integer.parseInt(s.split("=")[3]));
                System.out.println(2);
            }
        }
    }
}


